<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div style="float: right;margin-right: 17px;margin-top: 15px;">
        <el-button type="primary" size="mini" @click="addOpinionCollection()" v-if="typetemp!='1'&&stateControlBtn!='0'">新增征求意见</el-button>
        <el-button type="success" size="mini" @click="changeSubjectState()" v-if="typetemp=='1'">确认分配</el-button>
      </div>
      <div class="card-body">
        <avue-crud :data="subjectOpinionListData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @on-load="getResultList"
                   class="menu-min-height">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="opinionFeedback(scope.row,scope.index)">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">反馈结果</p>
            </div>
          </template>
        </avue-crud>
      </div>
      <el-dialog title="征求意见详情" :visible.sync="opinionDialogVisible" width="70%">
        <bostech-detail :detail-data="opinionDetailData"></bostech-detail>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="opinionDialogVisible = false">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </basic-container>
</template>

<script>
  import {getOpinionList} from "@/api/opinion";
  import {changeSubjectState} from "@/api/subject";
  import {typeMap,tableDictMap} from "@/views/opinion/const"
  import getOpinionDetail from "@/mixins/opinion/getOpinionDetail";

  export default {
    name: "opinionCollectionList",
    mixins: [getOpinionDetail()],
    created() {
      if(this.$route.query.stateControlBtn==undefined){
        this.stateControlBtn ='1';
      }else {
        this.stateControlBtn = this.$route.query.stateControlBtn
      }
      this.headerData.title = typeMap[this.$route.query.type];
      this.typetemp = this.$route.query.type;
      if(tableDictMap[this.$route.query.type]){
        this.tableoption.column = tableDictMap[this.$route.query.type]
      }
      window.opinionDetail = this.opinionDetail
    },
    data() {
      return {
        headerData: {
          title: '规划编制-征求意见'
        },
        stateControlBtn:'',
        opinionDialogVisible: false,
        subjectOpinionListData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth: 120,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "征求主题",
              prop: "title",
              cell: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="opinionDetail(\'' + row.opinionId + '\')">' + value + '</a>';
              },
            },
            {
              label: "截止日期",
              prop: "endDate",
              cell: true
            },
            {
              label: "创建人",
              prop: "createNickname",
              cell: true
            },
          ]
        },
        tableLoading: false,
        typetemp: '',
      }
    },
    methods: {
      // 课题详情跳转
      fileFeedback(row) {
        let src = `/fileFeedback/detail/${row.opinionId}`;
        this.$router.push({
          path: src
        })
      },
      getResultList(page) {
        this.tableLoading = true;
        getOpinionList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          relateId: this.$route.params.id,
          type: this.$route.query.type
        })).then(response => {
          this.subjectOpinionListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },
      // 发起征集意见
      addOpinionCollection() {
        let src = `/opinionCollection/add/${this.$route.params.id}`;
        this.$router.push({
          path: src,
          query: {
            type: this.$route.query.type,
            title:this.$route.query.title
          }
        })
      },
      // 征集意见详情
      opinionDetail(id) {
        this.getDetailData_opinion(id);
        this.opinionDialogVisible = true
      },
      // 反馈结果
      opinionFeedback(row, index) {
        let src = `/feedbackResult/list/${row.opinionId}`;
        this.$router.push({
          path: src,
          query: {
            targetId: row.targetId,
            type:this.$route.query.type
          }
        })
      },
      changeSubjectState() {
        this.$confirm("确定要确认分配吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          changeSubjectState(this.$route.query.subjectId, Object.assign({
            state: '5'
          })).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '确认成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(-1);
            }
          })
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
</style>
